﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Sogeti.QueryWrapper;
using Sogeti.VSExtention;

namespace Mskold.IterationManager
{
    class SettingsViewModel
    {

        public SettingsViewModel()
        {
            
        }

        public SettingsViewModel(IterationManagerConfig cfg)
        {
            Config = cfg;
        }

        public void Load(TeamExplorerIntergator te)
        {

            teamExplorer = te;
            Config= new IterationManagerConfig(teamExplorer);
            Config.Load();
        }
        public List<string> WorkItemTypes
        {
            get
            {
                List<string> lst = new List<string>();
                if (teamExplorer != null)
                {
                    TPWiWrapper wit = new TPWiWrapper(teamExplorer);
                    lst= wit.GetWorkItemTypes();
                }
                return lst;

            }
        }

        public List<string> WorkItemFields
        {
            get
            {
                List<string> lst = new List<string>();
                if (teamExplorer != null)
                {
                    TPWiWrapper wit = new TPWiWrapper(teamExplorer);
                    lst= wit.GetWorkItemFields(Config.ConfigStore.SprintWorkItemType, typeof(DateTime).Name);
                }
                return lst;
            }
        }

        public Dictionary<string, string> TeamQueryFolders
        {
            get
            {
                Dictionary<string, string> lst = new Dictionary<string, string>();
                if (teamExplorer != null)
                {
                    TPQueryWrapper queryWrp = new TPQueryWrapper(teamExplorer);
                    foreach (WiqlFolder fld in
                        queryWrp.ListFolders(teamExplorer.tpName + @"/Team Queries"))
                    {
                        lst.Add(fld.Path, fld.Name);
                    }
                }
           
                return lst;
            }
        }

        private IterationManagerConfig _config;

        public IterationManagerConfig Config
        {
            get { return _config; }
            set { _config = value; }
        }

        private TeamExplorerIntergator teamExplorer;
     
    }
}
